/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import service.BullCowService;

/** 
 *
 * @author Steven
 */
public class BullCowController extends SimpleFormController {

    public BullCowController() {
        //Initialize controller properties here or 
        //in the Web Application Context

        setCommandClass(Word.class);
        setCommandName("word");
        setSuccessView("bullCowView");
        setFormView("wordView");
    }
    
    private BullCowService bullCowService;

    public void setHelloService(BullCowService bullCowService) {
    this.bullCowService = bullCowService;
    }

    //Use onSubmit instead of doSubmitAction 
    //when you need access to the Request, Response, or BindException objects
    
    @Override
    protected ModelAndView onSubmit(Object command) throws Exception {
        Word word = (Word)command;
        ModelAndView mv = new ModelAndView(getSuccessView());
        mv.addObject("bullCowMessage", bullCowService.guessWord(word.getValue()));

        //Do something...
        return mv;
    }
    

}